package mysql

import (
	"context"
	"fmt"
	"vite-tsc-gin/api"

	"gorm.io/gorm"
)

type users struct {
	db *gorm.DB
}

func newUsers(ds *datastore) *users {
	return &users{ds.db}
}

func (u *users) Create(ctx context.Context, user *api.User) error {
	fmt.Println(user)
	return u.db.Create(user).Error
}
func (u *users) Get(ctx context.Context, username string) (*api.User, error) {
	var user api.User
	er := u.db.Where("username = ? and status = 1", username).First(&user).Error
	return &user, er
}
func (u *users) Update(ctx context.Context, user *api.User) error {
	return u.db.Save(user).Error
}
